Regular expression knowledge of the series, through the code example to illustrate the regular expression of knowledge, suggest that you follow the example hand to play again.
The source code download address for this
View code
Package RegEx;Import java. Io. ioexception;Import java. util. RegEx. matcher;Import java. util. RegEx. pattern;/*** Note: matcher is the main operation class of the regular expression. It contains the most important method for extraction and replacement. pattern i
The regular expression defines the link:Http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#sumApplication Examples:
Count the number of words in a Java string
public class Nn {public static void Main (string[] args) {String str= "This is a process";System.out.println (Str.split ("\\s+")
. (COM/CN) is an indefinite number of2. Regular expression: String regx = "\\[email protected]\\w{2,6} (\.[ a-za-z]{2,3}) + ";Analytical:\\w: all letters and numbers; +: The front appears 1 or more times; \\w{2,6}: \\w can only show 2-6\. : ‘.’ this character; [A-za-z]: all the letters; {2,3}: There are only 2-3 letters in front,(\. [A-za-z] {2,3}) +: ' + ' before content appears 1 or more timesAttention:A:
package regular expression; public class Rudolph {public static void main (string[] args) {//TODO auto-generated method stubstring[] Str = new string[]{"Rudolph", "[Rr]udolph", "[rr][aeiou][a-z]ol.*", "r.*"};for (String pattern:str) System.out.println (" Rudolph ". Matches (pattern)); for (String ss:str)//The data in the container str is traversed by one of the data of type String. SYSTEM.OUT.PRINTLN (ss);
Therefore, we need to clarify how many number segments have been opened. The country number segments are allocated as follows:Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188China Unicom: 130, 131, 132, 152, 155, 156, 185, 186China Telecom: 133, 153, 180, 189 (1349 Weitong)Now we can test the regular expression matching,Import java. io
For example: from the following stringOpening Hours: 11:30-21:30 Modified category Tags: wireless Internet access (8) can swipe (7) Friends (5) Family Gatherings (5) Business Dinners (4) Couples (4) Bring your own drinks (2 )Acquired in: 11:30-21:30Two digits: two digits-two digits: two digits therefore the regular expression:\\d{2}:\\d{2}-\\d{2}:\\d{2}The specif
1 /**2 * The first line matches the special characters;3 * The second line matches the beginning and the end have spaces;4 * The third line matches the end with a space5 * */6 PrivateBoolean Determinechar (String reqdata, String respdata) {7String reg = "@@|==|--|!| \\!|"8+ "\\s (union|and|or|where|exec|like|from|trancate|char|substr|ascii|count|into) \\s|" +9"\\b (Select|update|delete|insert|trancate|char|alter|substr|ascii|declare|exec|drop) \\s";TenPattern pattern = Pattern.compile (
Examples of the application of Java's regular expressions (see Java's application of the regular Expressions): Test code packagetest;/** * In string matches () method, the split () method uses regular expressions . * @author fhd001 */ publicclassregextest{ public Staticvoidmain (String[]args) { /* * Ordinary characters */ Stringstr1= "abc45abc345"; String
At the beginning, you have to say ^ and $ they are used to match the start and end of a string, respectively, as illustrated below
If you're a novice, guess you're canceling the regular expression 30 minute introductory tutorial
"^the": The beginning must have "the" string;
"Of despair$": The end must have a string of "of despair";
So
"^abc$": a string that requires the beginning of ABC and the end of ABC,
Example of jQuery regular expression-based form verification function, jquery Regular Expression
This document describes jQuery's form verification function based on regular expressions. We will share this with you for your refere
Python uses a regular expression to match the start of a string and print the example. python Regular Expression
This example describes how to use a regular
, 1}
{N} matches the previous expression n times. N is a non-negative integer.
{N,} matches the previous expression at least N times. N is a non-negative integer.
{N, m} matches the previous expression N-m times, and the NM values are non-negative integers.
[] Character class. For example, [123] indicates any num
Said so much, I believe that we all understand the use of the above methods, it is said that the regular expression of the grouping in Java is how to use.Start (), End (), group () has an overloaded method that is start (int i), end (int i), group (int i) is dedicated to grouping operations, and the Mathcer class also has a GroupCount () to return the numbe
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.